package com.sky.controller.user;

import com.sky.constant.ShopStatusConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController("userShopController") //如果不设置会跟admin/ShopController在IOC中重名,因为类名一样
@Slf4j
@Api(tags = "客户端店铺控制器")
@RequestMapping("/user/shop")
public class ShopController {

    @Resource
    RedisTemplate redisTemplate;

    @GetMapping("/status")
    @ApiOperation("获取店铺状态")
    public Result<Integer> getStatus(){
        log.info("[客户端获取营业状态] 开始读取redis");
        Object shop_status = redisTemplate.opsForValue().get(ShopStatusConstant.SHOP_STATUS);
        if(shop_status!=null){
            log.info("[客户端获取营业状态] 获取成功");
            return Result.success((Integer) shop_status);
        }else{
            log.info("[客户端获取营业状态] 获取失败");
            return Result.error("获取营业状态失败");
        }
    }
}
